﻿using System;
using System.Collections.Generic;
using System.Text;
using DTO;
using DAL;

namespace BUS
{
    public class HoaDonBanHangBUS
    {
        public static void INSERT(HoaDonBanHang D)
        {
            HoaDonBanHangDAL CTDHDAL = new HoaDonBanHangDAL();
            CTDHDAL.INSERT(D);
        }
        public static void UPDATE(HoaDonBanHang D)
        {
            HoaDonBanHangDAL CTDHDAL = new HoaDonBanHangDAL();
            CTDHDAL.UPDATE(D);
        }
        public static void UPDATE_TrangThai(int mahoadon, int trangthai)
        {
            HoaDonBanHangDAL CTDHDAL = new HoaDonBanHangDAL();
            CTDHDAL.UPDATE_TrangThai(mahoadon,trangthai);
        }
        public static void DELETE(int iD)
        {
            HoaDonBanHangDAL CTDHDAL = new HoaDonBanHangDAL();
            CTDHDAL.DELETE(iD);
        }
        public int MaHoaDonBanHangCuoiCung(string tendangnhap_nguoimua)
        {
            HoaDonBanHangDAL DAL = new HoaDonBanHangDAL();
            return DAL.MaHoaDonBanHangCuoiCung(tendangnhap_nguoimua);
        }
        public static HoaDonBanHangCollection GETALL()
        {
            HoaDonBanHangDAL CTDHDAL = new HoaDonBanHangDAL();


            int TotalRecords = 0;
            return CTDHDAL.GET("where 1=1", 0, 0,
                            HoaDonBanHangColumn.MaHoaDonBanHang.ToString(),
                            "ASC", out TotalRecords);
        }
        public static HoaDonBanHangCollection GET(string Where, int PageIndex, int PageSize, string OrderBy, string OrderDirection, out int TotalRecords)
        {
            HoaDonBanHangDAL CTDHDAL = new HoaDonBanHangDAL();
            return CTDHDAL.GET(Where, PageIndex, PageSize, OrderBy, OrderDirection, out TotalRecords);
        }
        public static HoaDonBanHang GetById(int iD)
        {
            int total = 0;
            HoaDonBanHangDAL DAL = new HoaDonBanHangDAL();
            HoaDonBanHangCollection Collection = DAL.GET("where " + HoaDonBanHangColumn.MaHoaDonBanHang.ToString() + "='" + iD + "'", 0, 0, HoaDonBanHangColumn.MaHoaDonBanHang.ToString(), "ASC", out total);
            if (Collection.Count > 0)
                return Collection[0];
            return null;
        }
    }
}
